package com.dyx.api.files.controller;

/**
 * Created by Administrator on 2017/8/1.
 */
import com.alibaba.fastjson.JSONObject;
import com.dyx.api.files.conf.RestTemplateConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.core.io.FileSystemResource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

//@RestController
//@EnableAutoConfiguration
//@Import(value = {RestTemplateConfig.class})
public class TestController {
//    @Autowired
//    RestTemplate restTemplate;
//    @Autowired
//    private Environment env;
//
//
//    /***********HTTP GET method*************/
//    @RequestMapping("")
//    public String hello(){
//        //String url = "http://localhost:8080/json";
//        String url = env.getProperty("rest.template.json");
//        JSONObject json = restTemplate.getForEntity(url, JSONObject.class).getBody();
//        return json.toJSONString();
//    }
//
//    @RequestMapping("/json")
//    public Object genJson(){
//        JSONObject json = new JSONObject();
//        json.put("descp", "this is spring rest template sample");
//        return json;
//    }
//
//    /**********HTTP POST method**************/
//    @RequestMapping("/postApi")
//    public Object iAmPostApi(@RequestBody JSONObject parm){
//        System.out.println(parm.toJSONString());
//        parm.put("result", "hello post");
//        return parm;
//    }
//
//    @RequestMapping("/post")
//    public Object testPost(){
//        //String url = "http://localhost:8080/postApi";
//        String url = env.getProperty("rest.template.postApi");
//        JSONObject postData = new JSONObject();
//        //传递的参数
//        postData.put("descp", "request for post");
//        JSONObject json = restTemplate.postForEntity(url, postData, JSONObject.class).getBody();
//        return json.toJSONString();
//    }
//
//    @RequestMapping("/testRest")
//    public String testRest(){
//        FileSystemResource file = new FileSystemResource(new File("C:\\Users\\Administrator\\Downloads\\id1-front.jpeg"));
//        //File file = new File("C:\\Users\\Administrator\\Downloads\\id1-front.jpeg");
//        JSONObject obj = new JSONObject();
//        obj.put("createUser",1l);
//        obj.put("belongUser",1l);
//        MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
//        param.add("file", file);
//        param.add("param", obj);
//        JSONObject result = restTemplate.postForEntity("http://localhost:8088/files/uploadFile", param, JSONObject.class).getBody();
//        System.out.println(result);
//        return result.toJSONString();
//    }


}
